home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / dpmigcc5.zip / RSX / SOURCE / SIGNALS.C < prev    next >
C/C++ Source or Header  |  1994-12-12  |  17KB  |  641 lines

  1. /*****************************************************************************
  2.  * FILE: signals.c                                 *
  3.  *                                         *
  4.  * DESC:                                     *
  5.  *    - signal handling                             *
  6.  *    - exception handler                             *
  7.  *    - DPMI 1.0 page fault handler                         *
  8.  *                                         *
  9.  * Copyright (C) 1993,1994                             *
  10.  *    Rainer Schnitker, Heeper Str. 283, 33607 Bielefeld             *
  11.  *    email: rainer@mathematik.uni-bielefeld.de                 *
  12.  *                                         *
  13.  *****************************************************************************/
  14.  
  15. #include <string.h>
  16. #include "PRINTF.H"
  17. #include "DPMI.H"
  18. #include "DPMI10.H"
  19. #include "RMLIB.H"
  20. #include "PROCESS.H"
  21. #include "SIGNALS.H"
  22. #include "START32.H"
  23. #include "CDOSX32.H"
  24. #include "EXCEP32.H"
  25. #include "ADOSX32.H"
  26. #include "COPY32.H"
  27. #include "RSX.H"
  28. #include "LOADPRG.H"
  29. #include "KDEB.H"
  30. #include "DOSERRNO.H"
  31.  
  32. #define SIGSA(no)   ((no)-1)
  33. #define SIGMASK(no) (1L<<((no)-1))
  34. #define SIGBLOCK    (~(SIGSA(SIGKILL)))
  35.  
  36. #define SA_NOTBSD   (SA_SYSV | SA_ACK)
  37.  
  38. /* local functions */
  39. static int exception2signal(WORD);
  40. static int do_signal(int);
  41. static void print_exception_exit(void);
  42. static void print_regs_exception(void);
  43.  
  44. extern char *sigtext[];
  45.  
  46. /*
  47. ** give back a signal no from a hardware exception fault no
  48. */
  49. static int exception2signal(WORD faultno)
  50. {
  51.     int signal;
  52.  
  53.     switch (faultno) {
  54.     case 0:
  55.     case 2:
  56.     case 4:
  57.     case 5:
  58.     case 6:
  59.     case 8:
  60.     case 10:
  61.     case 15:
  62.     signal = SIGILL;
  63.     break;
  64.     case 1:
  65.     case 3:
  66.     signal = SIGTRAP;
  67.     break;
  68.     case 7:
  69.     case 16:
  70.     signal = SIGFPE;
  71.     break;
  72.     case 9:
  73.     case 11:
  74.     case 12:
  75.     case 13:
  76.     case 14:
  77.     case 17:
  78.     signal = SIGSEGV;
  79.     break;
  80.     default:
  81.     signal = SIGSEGV;
  82.     break;
  83.     }
  84.  
  85.     return signal;
  86. }
  87.  
  88. /*
  89. ** set signal for one process
  90. */
  91. int send_signal(NEWPROCESS * p, int signal)
  92. {
  93.     if (!p || signal < 0 || signal >= MAX_SIGNALS)
  94.     return EMX_EINVAL;
  95.     p->sig_raised |= SIGMASK(signal);
  96.     return 0;
  97. }
  98.  
  99. static void check_pending(int signum)
  100. {
  101.     struct sigaction *p;
  102.  
  103.     p = signum - 1 + npz->sigaction;
  104.     if (p->sa_handler == SIG_IGN) {
  105.     if (signum == SIGCHLD)
  106.         return;
  107.     npz->sig_raised &= ~ SIGMASK(signum);
  108.         return;
  109.     }
  110.     if (p->sa_handler == SIG_DFL) {
  111.     if (signum != SIGCHLD)
  112.         return;
  113.     npz->sig_raised &= ~ SIGMASK(signum);
  114.     return;
  115.     }
  116. }
  117.  
  118. int sys_sigaction(int signum, DWORD action, DWORD oldaction)
  119. {
  120.     struct sigaction new_sa, *p;
  121.  
  122.     if (signum<1 || signum>=MAX_SIGNALS || signum==SIGKILL)
  123.     return -EMX_EINVAL;
  124.     p = signum - 1 + npz->sigaction;
  125.     if (action) {
  126.     if (verify_illegal(npz, action, sizeof(action)))
  127.         return -EMX_EINVAL;
  128.     cpy32_16(npz->data32sel, action, &new_sa, sizeof(struct sigaction));
  129.     new_sa.sa_mask |= SIGMASK(signum);
  130.     new_sa.sa_mask &= SIGBLOCK;
  131.     }
  132.     if (oldaction) {
  133.     if (verify_illegal_write(npz, oldaction, sizeof(oldaction)))
  134.         return -EMX_EINVAL;
  135.     cpy16_32(npz->data32sel, oldaction, p, sizeof(struct sigaction));
  136.     }
  137.     if (action) {
  138.     *p = new_sa;
  139.     check_pending(signum);
  140.     }
  141.     return 0;
  142. }
  143.  
  144. int sys_sigpending(DWORD set_addr)
  145. {
  146.     DWORD set = npz->sig_blocked & npz->sig_raised;
  147.  
  148.     if (verify_illegal_write(npz, set, 4))
  149.     return -EMX_EINVAL;
  150.     store32(npz->data32sel, set_addr, set);
  151.     return 0;
  152. }
  153.  
  154. int sys_sigprocmask(int how, DWORD set, DWORD oset)
  155. {
  156.     sigset_t new_set, old_set = npz->sig_blocked;
  157.  
  158.     if (set) {
  159.     if (verify_illegal(npz, set, sizeof(sigset_t)))
  160.         return -EMX_EINVAL;
  161.     new_set = read32(npz->data32sel, set) & SIGBLOCK;
  162.  
  163.     switch (how) {
  164.         case SIG_BLOCK:
  165.         npz->sig_blocked |= new_set;
  166.         break;
  167.         case SIG_UNBLOCK:
  168.         npz->sig_blocked &= ~new_set;
  169.         break;
  170.         case SIG_SETMASK:
  171.         npz->sig_blocked = new_set;
  172.         break;
  173.         default:
  174.         return -EMX_EINVAL;
  175.     }
  176.     }
  177.     if (oset) {
  178.     if (verify_illegal_write(npz, oset, sizeof(sigset_t)))
  179.         return -EMX_EINVAL;
  180.     store32(npz->data32sel, oset, old_set);
  181.     }
  182.     return 0;
  183. }
  184.  
  185. /*
  186. ** signal handler returned via syscall 0x10
  187. */
  188. int signal_handler_returned(void)
  189. {
  190.     DWORD signal, sig_blocked;
  191.     DWORD r;
  192.  
  193.     signal = read32(npz->data32sel, ESPORG);
  194.     if (opt_printall)
  195.     printf("return signal handler: %lX\n", signal);
  196.  
  197.     sig_blocked = read32(npz->data32sel, ESPORG + 4);
  198.  
  199.     /* unblock old signal mask, if not emx ack */
  200.     if (!(npz->sigaction[SIGSA(signal)].sa_flags & SA_ACK))
  201.     npz->sig_blocked = sig_blocked & ~SIGMASK(signal);
  202.  
  203.     r = read32(npz->data32sel, ESPORG + 8);    /* nop ; mov $7f10, %eax */
  204.     if (r != 0x7F07b890) {
  205.     puts("sigreturn: illegal frame");
  206.     return 1;
  207.     }
  208.     r = read32(npz->data32sel, ESPORG + 12);     /* int 0x21 */
  209.     if (r != 0x21cd0000) {
  210.     puts("sigreturn: illegal frame");
  211.     return 1;
  212.     }
  213.  
  214.     cpy32_16(npz->data32sel, ESPORG + 16, &(npz->regs), sizeof(REG386));
  215.  
  216.     if (AX == 0x7f0E) {     /* back from raise() */
  217.     EAX = ECX = 0;        /* put return values */
  218.     back_from_syscall();
  219.     return 1;
  220.     }
  221.     /*
  222.     ** if we had a hardware exception, we zero the user handler, to
  223.     ** prevent a exception loop to handler (may be changed in future)
  224.     */
  225.     if (signal == SIGSEGV || signal == SIGILL ||
  226.     signal == SIGFPE || signal == SIGTRAP) {
  227.     (npz->sigaction[SIGSA(signal)]).sa_handler = 0;
  228.     npz->sig_blocked &= ~SIGMASK(signal);
  229.     }
  230.  
  231.     return 1;
  232. }
  233.  
  234. /*
  235. ** called before return to user process
  236. */
  237. int check_signals(void)
  238. {
  239.     int i;
  240.     DWORD sigs;
  241.  
  242.     sigs = ~npz->sig_blocked & npz->sig_raised;
  243.     if (!sigs)
  244.     return 0;
  245.  
  246.     while (sigs) {
  247.     for (i = 1; i <= MAX_SIGNALS; i++) {
  248.         if (sigs & 1) {
  249.         if (do_signal(i))
  250.             break;        /* restart loop, if handler called */
  251.         }
  252.         sigs >>= 1;
  253.     }
  254.     sigs = ~npz->sig_blocked & npz->sig_raised;
  255.     }
  256.     return 0;
  257. }
  258.  
  259. #define SIGDFL_IGNORE        0
  260. #define SIGDFL_TERMINATE    1
  261. #define SIGDFL_CORE        2
  262.  
  263. static struct {
  264.     char *text;
  265.     char action;
  266. } sigdfl[MAX_SIGNALS] = {
  267.     { "SIGHUP",     SIGDFL_TERMINATE },
  268.     { "SIGINT",     SIGDFL_TERMINATE },
  269.     { "SIGQUIT",    SIGDFL_CORE },
  270.     { "SIGILL",     SIGDFL_CORE },
  271.     { "SIGTRAP",    SIGDFL_CORE },
  272.     { "SIGABRT",    SIGDFL_CORE },
  273.     { "SIGEMT",     SIGDFL_CORE },
  274.     { "SIGFPE",     SIGDFL_CORE },
  275.     { "SIGKILL",    SIGDFL_TERMINATE },
  276.     { "SIGBUS",     SIGDFL_CORE },
  277.     { "SIGSEGV",    SIGDFL_CORE },
  278.     { "SIGSYS",     SIGDFL_CORE },
  279.     { "SIGPIPE",    SIGDFL_TERMINATE },
  280.     { "SIGALRM",    SIGDFL_TERMINATE },
  281.     { "SIGTERM",    SIGDFL_TERMINATE },
  282.     { "SIGUSR1",    SIGDFL_IGNORE },
  283.     { "SIGUSR2",    SIGDFL_IGNORE },
  284.     { "SIGCHLD",    SIGDFL_IGNORE },
  285.     { "SIG19",      SIGDFL_IGNORE },
  286.     { "SIG20",      SIGDFL_IGNORE },
  287.     { "SIGBREAK",   SIGDFL_TERMINATE }
  288. };
  289.  
  290. void setup_frame(DWORD address, DWORD oldmask, int signal)
  291. {
  292.     DWORD code;
  293.  
  294.     if (ESP == ESPORG)        /* build stack-frame,if not */
  295.     ESP -= 12;
  296.  
  297.     /* save regs for handler return, put reg values on user stack */
  298.     cpy16_32(npz->data32sel, ESP - sizeof(REG386),
  299.          &(npz->regs), sizeof(REG386));
  300.     ESP -= sizeof(REG386);    /* sub register-frame */
  301.  
  302.     EIP = address;        /* sighandler address */
  303.  
  304.     ESP -= sizeof(long);    /* put code: int 0x21 */
  305.     store32(npz->data32sel, ESP, 0x21cd0000);
  306.     ESP -= sizeof(long);    /* put code: popl %eax ; movl $7f07, %eax */
  307.     store32(npz->data32sel, ESP, 0x7F07b890);
  308.     code = ESP;
  309.  
  310.     ESP -= sizeof(long);    /* put signal mask on user stack */
  311.     store32(npz->data32sel, ESP, oldmask);
  312.     ESP -= sizeof(long);    /* put signalno on user stack */
  313.     store32(npz->data32sel, ESP, signal);
  314.     ESP -= sizeof(long);    /* put return address: stack code */
  315.     store32(npz->data32sel, ESP, code);
  316.  
  317.     ESPORG = ESP;
  318.     ESP -= 12;            /* sub iret frame */
  319. }
  320.  
  321. /*
  322. ** check signals settings , change eip to signal handler
  323. */
  324. static int do_signal(int signal)
  325. {
  326.     DWORD address;
  327.     DWORD mask;
  328.  
  329. #ifdef CONFIG_KDEB
  330.     if (!opt_kdeb)
  331. #endif
  332.     /* if debugger: switch first */
  333.     if ((npz->p_flags & PF_DEBUG) && signal != SIGKILL && signal != SIGCLD) {
  334.     npz->wait_return = (signal << 8) | 127;
  335.     npz->p_flags |= PF_WAIT_WAIT;
  336.  
  337.     npz->p_status = PS_STOP;
  338.     npz->pptr->p_status = PS_RUN;        /* run debugger */
  339.     switch_context(npz->pptr);
  340.  
  341.     npz->p_status = PS_RUN;         /* continue child */
  342.     npz->wait_return = 0;
  343.  
  344.     if (signal == SIGTRAP) {
  345.         mask = ~ SIGMASK(signal);
  346.         npz->sig_raised &= mask;
  347.         npz->sig_blocked &= mask;
  348.         return 0;
  349.     }
  350.     }
  351.  
  352.     address = npz->sigaction[SIGSA(signal)].sa_handler;
  353.     if (opt_printall)
  354.     printf("do_signal %d handler %lX\n", signal, address);
  355.  
  356.     mask = SIGMASK(signal);
  357.     npz->sig_raised &= ~mask;        /* clear sig_raised */
  358.  
  359.     if (address == 1L)            /* ignore sig */
  360.     return 0;
  361.  
  362.     if (address == 0L) {
  363.     /* emx ignores SIGCLD, SIGCHLD, SIGUSR */
  364.  
  365.     if (sigdfl[SIGSA(signal)].action == SIGDFL_IGNORE)
  366.         return 0;
  367.     else if (sigdfl[SIGSA(signal)].action == SIGDFL_CORE) {
  368.         if (!opt_nocore)
  369.         write_core_file(npz);
  370.     }
  371.     printf("\nProcess terminated by %s\n", sigdfl[SIGSA(signal)].text);
  372.  
  373.     do_exit4c(signal);
  374.     return 1;
  375.     }
  376.  
  377.     /* ok, do user handler */
  378.     if (npz->sigaction[SIGSA(signal)].sa_flags & SA_SYSV)
  379.     npz->sigaction[SIGSA(signal)].sa_handler = 0L;
  380.     else
  381.     npz->sig_blocked |= mask;   /* set blocked */
  382.  
  383.     setup_frame(address, npz->sig_blocked, signal);
  384.  
  385.     /* BSD block others */
  386.     npz->sig_blocked |= npz->sigaction[SIGSA(signal)].sa_mask;
  387.  
  388.     return 1;
  389. }
  390.  
  391. long sys_signal(int signum, long handler)
  392. {
  393.     long old_handler;
  394.  
  395.     if (signum < 1 || signum >= MAX_SIGNALS || signum == SIGKILL)
  396.     return -1;
  397.  
  398.     old_handler = npz->sigaction[SIGSA(signum)].sa_handler;
  399.  
  400.     if (handler == SIG_ACK) {
  401.     npz->sig_blocked &= ~ SIGMASK(signum);
  402.     return old_handler;
  403.     }
  404.     else if (handler != SIG_DFL && handler != SIG_IGN)
  405.     if (verify_illegal(npz, handler, 4))
  406.         return -1;
  407.  
  408.     npz->sigaction[SIGSA(signum)].sa_handler = handler;
  409.     npz->sigaction[SIGSA(signum)].sa_flags = 0;
  410.     npz->sigaction[SIGSA(signum)].sa_mask = 0;
  411.  
  412.     if ((npz->uflags & 3) == 1)     /* system V */
  413.     npz->sigaction[SIGSA(signum)].sa_flags = SA_SYSV;
  414.     else if ((npz->uflags & 3) == 2)    /* BSD */
  415.     npz->sigaction[SIGSA(signum)].sa_flags = 0;
  416.     else                /* old EMX */
  417.     npz->sigaction[SIGSA(signum)].sa_flags = SA_ACK;
  418.  
  419.     return old_handler;
  420. }
  421.  
  422. char *exceptext[] =
  423. {
  424.     "division by zero",
  425.     "debug",
  426.     "NMI",
  427.     "breakpoint",
  428.     "overflow",
  429.     "bound check",
  430.     "invalid opcode",
  431.     "copro not availble",
  432.     "double fault",
  433.     "copro exception",
  434.     "invalid TSS",
  435.     "segment not present",
  436.     "stack fault",
  437.     "general protection",
  438.     "page fault",
  439.     "reserved",
  440.     "copro error",
  441.     "alignment error"
  442. };
  443.  
  444.  
  445. /*
  446. ** this function is called after hardware exceptions
  447. */
  448.  
  449. /* regs after exceptions */
  450. REG386 regf;
  451. EXCEPTION_10 reg_info;
  452.  
  453. void myexcep13(void)
  454. {                /* C exception handler */
  455.     int signal;
  456.  
  457. #ifdef CONFIG_KDEB
  458.     if (opt_kdeb && (WORD) regf.cs == code16sel && regf.faultno == 1) {
  459.     memcpy(&(RSX_PROCESS.regs), ®f, sizeof(REG386));
  460.     return KDEB_debug_handler();
  461.     }
  462. #endif
  463.  
  464.     if (opt_printall)
  465.     printf("Exception %d\n", (WORD) regf.faultno);
  466.  
  467.     /* test if we have a error in kernel, abort rsx */
  468.     /* future versions will just terminate the running process */
  469.  
  470.     if ((WORD) regf.cs == code16sel || (WORD) regf.ds == data16sel) {
  471.     printf("Kernel fault at %X %lX\n", (WORD) regf.cs, regf.eip);
  472.     printf("EAX=%08lX EBX=%08lX ECX=%08lX EDX=%08lX\n"
  473.            "EBP=%08lX ESP=%08lX  ESI=%08lX EDI=%08lX\n"
  474.            "CS=%04X DS=%04X ES=%04X SS=%04X\n",
  475.            regf.eax, regf.ebx, regf.ecx, regf.edx,
  476.            regf.ebp, regf.esp, regf.esi, regf.edi,
  477.      (WORD) regf.cs, (WORD) regf.ds, (WORD) regf.es, (WORD) regf.ss);
  478.     if (dpmi10) {
  479.         printf("cr2 = %lX\n", reg_info.cr2);
  480.         printf("pte = %lX\n", reg_info.pte);
  481.     }
  482.     printf("User Registers:\n");
  483.     npz->regs.faultno = regf.faultno;
  484.     print_exception_exit();
  485.     }
  486.  
  487.     /* user fault, copy saved regs to process table */
  488.     memcpy(&(npz->regs), ®f, sizeof(REG386));
  489.  
  490.     signal = exception2signal(FAULTNO);
  491.  
  492.     if (signal != SIGTRAP) {
  493.     printf("process %d get hardware fault %d (%s) at %lX\n",
  494.            npz->pid, FAULTNO, exceptext[FAULTNO], EIP);
  495.     if (opt_printall) {
  496.         print_regs_exception();
  497.         if (dpmi10) {
  498.         printf("cr2 = %lX\n", reg_info.cr2);
  499.         printf("offset = %lX\n", reg_info.cr2 - npz->memaddress);
  500.         printf("pte = %lX\n", reg_info.pte);
  501.         }
  502.     }
  503.     }
  504.     send_signal(npz, signal);
  505.  
  506.     /* then, check_signal() is called (see excep32.asm) */
  507. }
  508.  
  509. static void print_regs_exception(void)
  510. {
  511.     printf("selector=%lX  errbits: %X\n"
  512.        "cs:eip=%04X:%08lX eflags=%08lX\n"
  513.        "eax=%08lX ebx=%08lX ecx=%08lX edx=%08lX\n"
  514.        "ebp=%08lX esp=%08lX  esi=%08lX edi=%08lX\n"
  515.        "cs=%04X ds=%04X es=%04X ss=%04X fs=%04X gs=%04X\n",
  516.        ERR & ~7L, (WORD) ERR & 7,
  517.        CS, EIP, EFLAGS,
  518.        EAX, EBX, ECX, EDX,
  519.        EBP, ESP, ESI, EDI,
  520.        CS, DS, ES, SS, FS, GS);
  521. }
  522.  
  523. static void print_exception_exit()
  524. {
  525.     printf("PROTECTION FAULT  %d :\n", FAULTNO);
  526.     print_regs_exception();
  527.     shut_down(3);
  528. }
  529.  
  530.  
  531. /*
  532. ** DPMI 1.0 support, damand paging
  533. **
  534. ** only called, if start32.c sets page_fault() function
  535. */
  536.  
  537. /*
  538. ** commit page, if legal address
  539. ** page in text, data
  540. ** return 1, if real page-fault
  541. */
  542.  
  543. static unsigned char pagein_buffer[4096];
  544.  
  545. int swapper(void)
  546. {
  547.     DWORD offset;
  548.     NEWPROCESS *proc;
  549.     WORD page = 1 + 8;        /* commit & read/write */
  550.     int handle;
  551.  
  552.     if ((WORD) reg_info.cs == code16sel) {
  553.     /* copy in kernel, find current process */
  554.     for (proc = &FIRST_PROCESS; proc <= &LAST_PROCESS; proc++) {
  555.         if (!proc->code32sel)
  556.         continue;
  557.         if ((reg_info.cr2 > proc->memaddress) &&
  558.         (reg_info.cr2 < proc->memaddress + proc->membytes))
  559.         break;
  560.     }
  561.     if (proc > &LAST_PROCESS) {
  562.         if (opt_printall) {
  563.         puts("swapper: cannot find process");
  564.         printf("pagefault in %04X\n", (WORD) reg_info.cs);
  565.         printf("cr2 %08lX\n", reg_info.cr2);
  566.         printf("pte %X err %X\n", (WORD) reg_info.pte, (WORD) reg_info.error_code);
  567.         }
  568.         return 1;
  569.     }
  570.     } else
  571.     proc = npz;
  572.  
  573.     offset = (reg_info.cr2 - proc->memaddress) & ~0xFFFL;
  574.  
  575. #if 0
  576.     if (opt_printall) {
  577.     printf("process %d : pagefault in %04X\n", proc->pid, (WORD) reg_info.cs);
  578.     printf("cr2 %08lX, pageoffset %08lX\n", reg_info.cr2, offset);
  579.     printf("pte %X err %X\n", (WORD) reg_info.pte, (WORD) reg_info.error_code);
  580.     printf("memaddress = %lX handle = %lX\n", proc->memaddress, proc->memhandle);
  581.     }
  582. #endif
  583.  
  584.     if (proc->pid == 0)
  585.     return 1;
  586.  
  587.     handle = (int) proc->filehandle;
  588.  
  589.     /* text */
  590.     if (offset >= proc->text_start && offset < proc->text_end) {
  591.     if ((WORD) reg_info.cs != code16sel && (reg_info.error_code & 2))
  592.         return 1;
  593.     if (ModifyPageAttributes(proc->memhandle, offset, 1, &page))
  594.         return 1;        /* better:readonly */
  595.     if (handle == 0)    /* forked process */
  596.         return 0;
  597.     rm_lseek(handle, proc->text_off + (offset - proc->text_start), SEEK_SET);
  598.     if (rm_read(handle, pagein_buffer, 4096) != 4096)
  599.         return 1;
  600.     cpy16_32(proc->data32sel, offset, pagein_buffer, 4096L);
  601.     page = 1;
  602.     if (ModifyPageAttributes(proc->memhandle, offset, 1, &page))
  603.         return 1;
  604.     return 0;
  605.     } else
  606.      /* bss */ if (offset >= proc->bss_start && offset < proc->bss_end) {
  607.     if (ModifyPageAttributes(proc->memhandle, offset, 1, &page))
  608.         return 1;
  609.     if (handle == 0)    /* forked process */
  610.         return 0;
  611.     bzero32(proc->data32sel, offset, 4096L);
  612.     return 0;
  613.     } else
  614.      /* data */ if (offset >= proc->data_start && offset < proc->data_end) {
  615.     if (ModifyPageAttributes(proc->memhandle, offset, 1, &page))
  616.         return 1;
  617.     if (handle == 0)    /* forked process */
  618.         return 0;
  619.     rm_lseek(handle, proc->data_off + (offset - proc->data_start), SEEK_SET);
  620.     if (rm_read(handle, pagein_buffer, 4096) != 4096)
  621.         return 1;
  622.     cpy16_32(proc->data32sel, offset, pagein_buffer, 4096L);
  623.     return 0;
  624.     } else
  625.      /* heap */ if (offset >= proc->init_brk && offset < proc->brk_value) {
  626.     if (ModifyPageAttributes(proc->memhandle, offset, 1, &page))
  627.         return 1;
  628.     if (handle == 0)    /* forked process */
  629.         return 0;
  630.     if (proc->p_flags & PF_DJGPP_FILE)
  631.         bzero32(proc->data32sel, offset, 4096L);
  632.     return 0;
  633.     } else
  634.      /* stack */ if (offset >= proc->brk_value && offset <= proc->membytes) {
  635.     if (ModifyPageAttributes(proc->memhandle, offset, 1, &page))
  636.         return 1;
  637.     return 0;
  638.     } else
  639.     return 1;
  640. }
  641.